<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Eloquent底层实现数组形式访问
 * @author 张皓旻
 *
 */
class Eloquent_arrayaccess implements ArrayAccess
{
    /**
     * @param mixed $offset 键(缺省参数时$offset为null, 如: $foo[] = 'bar', $offset === null)
     * @param mixed $value  值
     * @see ArrayAccess::offsetSet()
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        if (is_null($offset))
        {
            $this->_attributes[] = $value;
        }
        else
        {
            $this->_attributes[$offset] = $value;
        }
    }
    
    public function offsetExists($offset)
    {
        return isset($this->_attributes[$offset]);
    }
    
    public function offsetUnset($offset)
    {
        unset($this->_attributes[$offset]);
    }
    
    public function offsetGet($offset)
    {
        return isset($this->_attributes[$offset]) ? $this->_attributes[$offset] : null;
    }   
}